package com.yzw.hello.model.pojos.system.role;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.yzw.hello.model.pojos.system.authority.Authority;
import com.yzw.hello.model.pojos.system.user.User;

@Entity
@Table(name = "role")
public class Role {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	@Column(nullable = false, updatable = true, length = 50)
	@NotNull
	@Length(max = 50, message = "名称不能超过{max}")
	private String name;
	
	@ManyToMany
	@JoinTable(
			name = "role_user",
			joinColumns = @JoinColumn(name = "rid")
			,inverseJoinColumns = @JoinColumn(name = "uid"))
	private Set<User> users;
	
	@OneToMany(mappedBy = "role",cascade = CascadeType.ALL)
	private Set<Authority> authorities;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}
	
}
